package com.yhx.controller;

import com.yhx.iservice.IOrderService;
import com.yhx.pojo.ListOrder;
import com.yhx.pojo.Order;
import com.yhx.pojo.OrderInfo;
import com.yhx.utils.MessageConstant;
import com.yhx.utils.Result;
import org.apache.dubbo.config.annotation.Reference;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("order")
public class OrderController {
    @Reference
    private IOrderService iOrderService;
    @PostMapping("listpage")

    public Result listpage(@RequestBody ListOrder listOrder){
        try {

            List<OrderInfo> pagelist = iOrderService.pagelist(listOrder.getName(), listOrder.getTel(),
                    listOrder.getDate(), listOrder.getPageNum(), listOrder.getPageSize());
            Long aLong = iOrderService.currentPage(listOrder.getName(), listOrder.getTel(), listOrder.getDate());
            return new Result(true, MessageConstant.ORDERSETTING_SUCCESS,pagelist,aLong);
        } catch (Exception e) {
            e.printStackTrace();
            return new Result(false, MessageConstant.ORDERSETTING_FAIL);
        }
    }

    @GetMapping("/between")
    public Result orderByStartTimeAndEndTime(String active,int pageNum,int pageSize){
        try {
            Result result = iOrderService.orderByTime(active, pageNum, pageSize);

            return result;
        } catch (Exception e) {
            e.printStackTrace();
            return new Result(false, "查询失败");
        }
    }
    @PostMapping("list")
    public Result listOrder(@RequestBody ListOrder listOrder,String active){
        try {
            Result result = iOrderService.pageList(active, listOrder.getName(), listOrder.getTel(), listOrder.getDate(), listOrder.getPageNum(), listOrder.getPageSize());
            return result;
        } catch (Exception e) {
            e.printStackTrace();
            return new Result(false, "查询订单信息失败");
        }
    }
    @PutMapping("/{id}")
    public Result update(@PathVariable int id){
        try {
            Order byid = iOrderService.getByid(id);
            Result update = iOrderService.update(byid);
            return update;
        } catch (Exception e) {
            e.printStackTrace();
            return new Result(false, "修改状态失败");
        }
    }

}
